# 构建阶段
FROM python:3.9-slim as builder

WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

COPY pyproject.toml poetry.lock ./
RUN pip install --no-cache-dir poetry==2.1.2 && \
    poetry config virtualenvs.in-project true && \
    poetry install --no-interaction --no-ansi

# 运行阶段
FROM python:3.9-slim

WORKDIR /app/fdp
ENV PATH="/app/fdp/.venv/bin:$PATH"

COPY --from=builder /app/.venv /app/fdp/.venv
COPY fdp/start.sh /app/fdp/start.sh

RUN chmod +x /app/fdp/start.sh && \
    mkdir -p /app/fdp/logs

COPY . .

EXPOSE 8000
CMD ["/app/fdp/start.sh"]